package com.dog.basics.admin.controller.common;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dog.basics.bean.dto.admin.common.BannerGenusAddDto;
import com.dog.basics.bean.dto.admin.common.BannerGenusEditDto;
import com.dog.basics.bean.model.common.SysBannerGenus;
import com.dog.basics.bean.vo.admin.common.BannerGenusVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.R;
import com.dog.basics.service.common.ISysBannerGenusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import ma.glasnost.orika.MapperFacade;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 广告所属地方 前端控制器
 * </p>
 *
 * @author fengjukang
 * @since 2019-12-13
 */
@RestController
@RequestMapping("/pc/banner/genus")
@Api(value = SwaggerConstants.COMMON+"广告所属地方模块", tags = SwaggerConstants.COMMON+"广告所属地方模块")
@AllArgsConstructor
public class SysBannerGenusController {
    private final ISysBannerGenusService sysBannerGenusService;
    private final MapperFacade mapperFacade;

    /**
     * @Description: 广告所属地方模块
     * @Param: DeviceTypeFromDto
     * @return: IPage<DeviceTypeVo>
     * @Author: wph
     * @Date:
     */
    @ApiOperation(value = "广告所属地方模块", notes = "pc:bannerGenus:page")
    @GetMapping
    @PreAuthorize("@pms.hasPermission('pc:bannerGenus:page')")
    public R<List<BannerGenusVo>> page() {
        List<SysBannerGenus> list = sysBannerGenusService.list(Wrappers.<SysBannerGenus>lambdaQuery().orderByDesc(SysBannerGenus::getCreateTime));
        List<BannerGenusVo> newList =  mapperFacade.mapAsList(list,BannerGenusVo.class);
        return R.ok(newList);
    }

    /**
     * @Description 增加广告所属地方
     * @Author  zhangmr
     * @Date   2020/7/27 0027 下午 15:25
     * @Param
     * @Return
     * @Exception
     *
     */
    @SysLog("增加广告所属地方")
    @ApiOperation(value = "增加广告所属地方", notes = "pc:bannerGenus:save")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('pc:bannerGenus:save')")
    public R<Boolean> save(@Valid @RequestBody BannerGenusAddDto obj) {
        return R.ok( sysBannerGenusService.saveObj(obj));
    }

    /**
     * @Description: 修改广告所属地方
     * @Param: PlateEditDto
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @SysLog("修改广告所属地方")
    @ApiOperation(value = "修改广告所属地方", notes = "pc:bannerGenus:edit")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('pc:bannerGenus:edit')")
    public R<Boolean> edit(@Valid @RequestBody BannerGenusEditDto obj) {
        return R.ok(sysBannerGenusService.editObj(obj));
    }


    /**
     * @Description: 删除广告所属地方
     * @Param: ids
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @SysLog("删除广告所属地方")
    @ApiOperation(value = "删除广告所属地方", notes = "pc:bannerGenus:delete")
    @ApiImplicitParam(value = "广告所属地方Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('pc:bannerGenus:delete')")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.ok( sysBannerGenusService.deleteObj(id));
    }
}
